<template>
  <!-- 学校校区管理 -->
  <div class="app-container">
    <!-- 搜索 -->
    <el-card class="search-card">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        class="formBox"
        label-width="100px"
      >
        <el-form-item label="批次号" prop="batchId">
          <el-input placeholder="请输入批次号" v-model="queryParams.batchId" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="请选择状态"
            @keyup.enter.native="handleQuery"
          >
            <el-option label="导入成功" value="1" />
            <el-option label="导入失败" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="批次时间">
          <el-date-picker
            v-model="date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >
            搜索
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 按钮 -->
    <el-card class="box-card" style="margin-top: 10px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="buttonMethod(1)"
            v-hasPermi="['studentManage:studentExport:import']"
          >
            批量导入
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-card>
    <!-- 列表 -->
    <el-card class="table-card" style="margin-top: 10px">
      <el-table :data="dataList" stripe border>
        <el-table-column label="批次号" prop="batchId" />
        <el-table-column label="批次时间" prop="batchTime" />
        <el-table-column label="状态" prop="status">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == '1'">导入成功</el-tag>
            <el-tag v-if="scope.row.status == '2'" type="danger">导入失败</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="类型" prop="type" />
        <el-table-column label="操作人" prop="createAt" />
        <!-- <el-table-column label="审核人" prop="approval" /> -->
        <!-- <el-table-column label="备注" prop="merchantName" /> -->
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="buttonMethod(2, scope.row)"
              v-hasPermi="['studentManage:studentExport:look']"
              >查看
            </el-button>
            <el-button
              size="mini"
              type="text"
              @click="buttonMethod(3, scope.row)"
              v-if="scope.row.status == '2'"
              v-hasPermi="['studentManage:studentExport:againExport']"
              >重新导入
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 导入 -->
    <el-dialog :title="title" :visible.sync="status" width="30%">
      <el-form label-width="120px" size="small" class="formBox">
        <el-row class="mt_10">
          <el-col :span="24" style="text-align: center">
            <file-upload
              action="/system/log/upload"
              @success="uploadSuccessFun"
            ></file-upload>
          </el-col>
          <el-col :span="24" class="mt_20" style="text-align: center; font-size: 12px">
            <el-divider></el-divider>
            <div class="mt_20">
              注：严格按照模版提供的格式要求填写，请勿修改模版以防无法导入或导入错误!
            </div>
          </el-col>
          <el-col :span="24" class="mt_10" style="text-align: center">
            <el-button @click="downloadsFileFun">下载系统提供的模版</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { systemLogList, systemLogRepeatUpload } from "@/api/studentManage";
export default {
  name: "",
  data() {
    return {
      status: false,
      title: "",
      dataList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchId: null,
        status: null,
        startDate: null,
        endDate: null,
      },
      date: [],
      queryForm: {},
      total: 0,
      showSearch: true,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取列表数据
    getList() {
      var that = this;
      var data = this.queryParams;
      if (this.date.length > 0) {
        data.startDate = this.date[0];
        data.endDate = this.date[1];
      }
      data.newsImport = 1;
      console.log(data, "asadasd");
      systemLogList(data).then((res) => {
        if (res.code == 200) {
          that.dataList = res.rows;
          that.total = res.total;
        }
      });
    },
    /**
     * 按钮点击事件处理方法
     */
    buttonMethod(options, value) {
      //options 等于 1
      if (options == 1) {
        this.queryForm = {};
        this.title = "批量导入";
        this.status = true;
      }
      //options 等于 2 关闭弹窗
      else if (options == 2) {
        this.$router.push("/enrollStudents/detail/role/" + value.batchId);
      }
      //options 等于 3 关闭弹窗
      else if (options == 3) {
        systemLogRepeatUpload(value.batchId).then((res) => {
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: res.msg,
            });
            this.resetQuery();
          } else {
            this.$message({
              type: "error",
              message: res.msg,
            });
          }
        });
      }
    },
    uploadSuccessFun() {
      this.status = false;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /**
     * 处理查询请求
     *
     * 将查询参数中的页码重置为1，并调用getList方法获取列表数据
     */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /**
     * 重置查询表单并重新执行查询操作
     */
    resetQuery() {
      this.resetForm("queryForm");
      this.date = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        batchId: null,
        status: null,
        startDate: null,
        endDate: null,
      };
      this.handleQuery();
    },
    /**
     * 下载学生导入模板文件
     */
    downloadsFileFun() {
      this.download("/system/log/download", {}, `新生导入模板.xlsx`);
    },
  },
};
</script>
<style>
.width_100 {
  width: 100%;
}
.mt_10 {
  margin-top: 10px;
}
.mt_20 {
  margin-top: 20px;
}
.el-divider--horizontal {
  margin: 4px 0 !important;
}
</style>
